<?php
/**
 * Zend_Service_Netflix_Review Class
 *
 * @author Armando Padilla, armando_padilla_81@yahoo.com
 * @package Zend_Service_Netflix
 * 
 */ 

class Zend_Service_Netflix_Review {

	/**
	 * Review Id.
	 *
	 * @var int $reviewId
	 */
	public $id;
	
	/**
	 * Actual review writen by the user.
	 *
	 * @var String $writeUp
	 */
	public $writeUp;
	
	/**
	 * Date review was updated.
	 *
	 * @var String $updatedDate.
	 */
	public $updatedDate;
	
	/**
	 * User's Rating of title.
	 *
	 * @var int $userRating
	 */
	public $userRating;
	
	/**
	 * Helpful. Number of votes indicating
	 * the review was helpful.
	 *
	 * @var int $helpful
	 */
	public $helpful;
	
	/**
	 * Not Helpful. Number of votes indicating
	 * the review was NOT helpful.
	 *
	 * @var int $notHelpful
	 */
	public $notHelpful;
	
	
	/**
	 * Title of the title.
	 *
	 * @var String
	 */
	public $title;
	
	/**
	 * Title API Ref URL.
	 *
	 * @var String
	 */
	public $titleIDAsURL;
	
	/**
	 * Title ID
	 *
	 * @var String
	 */
	public $titleID;
	
	
	public function __construct(){
		
		//Intantiate new Netflix_Title object
		$this->title = new Netflix_Title();
		
	}
	
	
	/**
	 * Load data from XML.
	 * 
	 * @param SimpleXMLElement $simpleXMLObject
	 */
	public function loadXML(SimpleXMLElement $simpleXMLObject){
		
		//Set property information.
		$this->writeUp 	  = (string)$simpleXMLObject->write-up;
		$this->updated 	  = (string)$simpleXMLObject->updated;
		$this->userRating = (string)$simpleXMLObject->user_rating;
		$this->helpful    = (string)$simpleXMLObject->not_helpful;
		$this->reviewId   = (string)$simpleXMLObject->review_id;
		$this->title      = (string)$simpleXMLObject->title['regular'];
	
		$xml = simplexml_load_string($simpleXMLObject);
		
		//Get the title URL
		$links = $xml->xpath("link[@ref='http://schemas.netflix.com/id']");
		foreach($links as $link){
			$this->titleIDAsURL = $link['href'];
			$this->titleID 	    = Zend_Service_Netflix_Utils::parseTitleId((string)$link['href']);
		}
		
	}

	
}